<?php
require("../models/webconfig.php");
require("../models/class.connection.php");
require("../models/entities/class.ProductEntity.php");
require("../models/repositories/class.ProductRepository.php");
include("../library/library.pager.php");
$productRepository = new ProductRepository();
$productName = "";
$arrColor = array();
$arrCategoryID = array();
if (isset($_GET['category_IDs'])) {
    if ($_GET['category_IDs'] != "-Any-") {
        $arrCategoryID = explode('|', $_GET['category_IDs']);
    }
}
if (isset($_GET['colors'])) {
    if ($_GET['colors'] != "-Any-") {
        $arrColor = explode('|', $_GET['colors']);
    }
}
if (isset($_GET['productName'])) {
    if ($_GET['productName'] != "-Any-") {
        $productName = $_GET['productName'];
    }
}
$curPage = 1;
if (isset($_GET['page'])) {
    if (is_numeric($_GET['page']))
        $curPage = $_GET['page'];
}
$totalItems = 0;
$results = $productRepository->SearchProductPager($curPage, 9, $arrCategoryID, $arrColor, $productName, $totalItems);
$generateLink = GenerateLink($totalItems, 5, 9, $curPage);
?>
<div class="loading"></div>
<div class="pagination pagination-left">
    <div class="results">
        <span>
            Kết quả từ <?php echo (($curPage - 1) * 9 + (count($results) > 0 ? 1 : 0)); ?> - <?php echo (($curPage - 1) * 9 + count($results)); ?> của <?php echo $totalItems ?>
        </span>
    </div>
    <ul class="pager"><?php echo $generateLink ?></ul>
</div>
<div class="clearall"></div>
<table id="tblProducts" cellpadding="0" cellspacing="0">
<?php
$count = 0;
while ($count < count($results)) {
?>
        <tr class="productsRow">
<?php
    for ($i = $count; $i < count($results); $i++) {
?>
            <td class="productCell">
                <div><a class="link1" href="#"><?php echo $results[$i]->Name_s; ?></a></div>
                <div class="clearall" style="margin-top:10px;"></div>
                <div style="width:207px; text-align:center; border:1px solid #ebeaea; padding:5px 0 5px 0;">
        <?php
        $arr = explode('|', $results[$i]->ImageSrc_s);
        ?>
                <a href="#"><img class="product1" alt="" src="../content/images/Products/<?php echo $results[$i]->Code_s; ?>/<?php echo $arr[0]; ?>" /></a>
            </div>
            <div class="clearall" style="margin-top:10px;"></div>
            <div style="float:left; width:167px; padding:0 20px 0 20px;">
                <table cellpadding="0" cellspacing="0" border="0" class="cont_body_table_2" style="float:left; width:97px;">
                    <tr>
                        <td><img src="../content/images/cont_body_corn_tl_2.gif" border="0" alt="" width="10" height="10" /></td>
                        <td width="100%" class="cont_body_tall_t_2"><img src="../../Content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                        <td><img src="../content/images/cont_body_corn_tr_2.gif" border="0" alt="" width="10" height="10" /></td>
                    </tr>
                    <tr>

                        <td class="cont_body_tall_l_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                        <td width="100%" class="cont_body_td_2"><span class="productSpecialPrice"><?php echo number_format($results[$i]->Price_f); ?><br />VNÐ</span></td>
                        <td class="cont_body_tall_r_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                    </tr>
                    <tr>
                        <td><img src="../content/images/cont_body_corn_bl_2.gif" border="0" alt="" width="10" height="10" /></td>
                        <td width="100%" class="cont_body_tall_b_2"><img src="../content/images/spacer.gif" border="0" alt="" width="1" height="1" /></td>
                        <td><img src="../content/images/cont_body_corn_br_2.gif" border="0" alt="" width="10" height="10" /></td>
                    </tr>
                </table>
                <div style="float:left; width:55px; margin:0 0 0 15px;">
                                <a href="../views/detail.php?id=<?php echo $results[$i]->Code_s; ?>">
                                    <div class="detail">
                                        Chi tiết
                                    </div>
                                </a>
                                <div class="clearall"></div>
                                <a href="../views/Cart.php?id=<?php echo $results[$i]->Code_s; ?>">
                                <div class="addToCart" style="margin:5px 0 0 0; cursor:pointer;">
                                    Mua
                                </div>
                                </a>
                            </div>
            </div>
        </td>
<?php
        if (++$count % 3 == 0)
            break;
    }
?>
    </tr>
<?php
}
?>	
</table>